Exceptional Cases When Working With Color Devices
If your application always specifies colors in
RGBColor
records, Color QuickDraw automatically handles the colors on both indexed and direct devices. However, if your application does not specify colors in
RGBColor
records, your application may need to create and use special-purpose
CGrafPort
,
PixMap
, and
GDevice
records with the routines described in the chapter "Offscreen Graphics Worlds."
If your application must work with
CGrafPort
,
PixMap
, and
GDevice
records in ways beyond the scope of the routines described elsewhere in this book, the following guidelines may aid you in adapting Color QuickDraw to color graphics devices.
-
Don't draw directly to the screen. Create your own offscreen graphics world (as described in the chapter "Offscreen Graphics Worlds") and use the
CopyBits
,
CopyMask
, or
CopyDeepMask
routine (described in the chapter "Color QuickDraw") to transfer the image to the screen.
-
Don't directly change the
fgColor
or
bkColor
fields of a
GrafPort
record and expect them to be used as the pixel values. Color QuickDraw recalculates these values for each graphics device. If you want to draw with a color with a particular
index value,
use a palette with explicit colors, as described in
Inside Macintosh: Advanced Color Imaging
. For device-independent colors, use the
RGBForeColor
and
RGBBackColor
procedures, described in the chapter "Color QuickDraw" in this book.
-
Don't copy a
GDevice
record's
PixMap
record. Instead, use the
NewPixMap
function or the
CopyPixMap
procedure, and fill all the fields. (These routines are described in the chapter "Color QuickDraw.") The
NewPixMap
function returns a
PixMap
record that is cloned from the
PixMap
record pointed to by the global variable
TheGDevice
. If you don't want a copy of the main screen's
PixMap
record--for example, you want one that is a different pixel depth--then you must fill out more fields than just
pixelSize
: you must fill out the
pixelType
,
cmpCount
, and
cmpSize
fields. Set the
pmVersion
field to 0 when initializing your own
PixMap
record. For future compatibility you should also set the
packType
,
packSize
,
planeBytes
, and
pmReserved
fields to 0. Don't assume a
PixMap
record has a color table--a pixel map for a direct device doesn't need one. For compatibility, a
PixMap
record for a direct device should have a dummy handle in the
pmTable
field that points to a
ColorTable
record with a seed value equal to
cmpSize
¥
cmpCount
and a
ctSize
field set to 0.
-
Fill out all the fields of a new
GDevice
record. When creating an offscreen
GDevice
record by calling
NewGDevice
with the
mode
parameter set to -1, you must fill out the fields of the
GDevice
record (for instance, the
gdType
field) yourself. If you want a copy of an existing
GDevice
record, copy the
gdType
field from it. If you explicitly want an indexed device, assign the
clutType
constant to the
gdType
field.
© 1997 Apple Computer, Inc.Previous | Chapter Top | Chapter Contents | Next